import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebFilter(filterName = "AurthFilter")
public class AurthFilter extends HttpFilter {
    @Override
    protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException {

	HttpSession session= req.getSession(true);
	System.out.println(req.getRequestURL());
	if(session.isNew())
	{
	    res.sendRedirect("index.jsp");
	}else if (req.getRequestURL().equals("http://localhost:8080/login/dgut"))
	{
	    if(req.getParameter("token") == null)
		res.sendRedirect("https://cas.dgut.edu.cn?appid=javaee");

	}

	chain.doFilter(req,res);
    }
}
